package swa.telco.impl;

import java.util.Collection;

import swa2012.telco.broker.BrokerCallback;
import swa2012.telco.broker.beans.Client;
import swa2012.telco.broker.beans.Message;
import swa2012.telco.broker.beans.ReceiveMessageStatus;

public class ImplBrokerCallback implements BrokerCallback {
	
	private MessageContainer msgContainer;
	private OnlineClients onlineClients;
	
	public ImplBrokerCallback(MessageContainer msgContainer, OnlineClients onlineClients){
		this.msgContainer = msgContainer;
		this.onlineClients = onlineClients;
	}

	@Override
	public ReceiveMessageStatus receiveMessage(Message msg) {
		try{
			msgContainer.add(msg);
		}catch (Exception e){
			e.printStackTrace();
			return ReceiveMessageStatus.RECEIVE_MESSAGE_ERROR;
		}
		return ReceiveMessageStatus.RECEIVE_MESSAGE_OK;
	}

	@Override
	public Collection<Client> listClients() {
		return onlineClients.getClients();
	}

	@Override
	public boolean ping() {
		return true;
	}

}
